package zhangcy.day0109.qingyoutravel.service;

import zhangcy.day0109.qingyoutravel.constants.TourRouteStatus;
import zhangcy.day0109.qingyoutravel.dao.TourRouteDao;
import zhangcy.day0109.qingyoutravel.po.TourRoute;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.List;
import java.util.Scanner;

/**
 *
 */
public class TourRouteMgr {
    // 定义Logger日志实例
//    private Logger logger = Logger.getLogger(UserMgr.class);

    public void showTourRouteInfo(TourRouteDao tourRouteDao, Scanner sc){
        System.out.println("显示所有景点信息");
        List<TourRoute> tourRoutes = tourRouteDao.queryAllTourRoutes();
        System.out.println("旅游路线名称\t类型\t价格(元)\t咨询电话\t咨询人\t创建日期");
        for (TourRoute t : tourRoutes){
            System.out.println(t.getTrName() + "\t" + TourRouteStatus.getTourRouteStatusByCode(t.getTrType()).getValue() + "\t" + t.getTrPrice()
                        + "\t" + t.getTrPhone() + "\t" + t.getTrUser() + "\t" + t.getCreateTime());
        }
    }

    public void saveTourRouteInfo(TourRouteDao tourRouteDao, Scanner sc) {
        LocalDate date = LocalDate.now();
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
        TourRoute tourRoute = new TourRoute();
        System.out.print("请输入旅游路线名称：");
        tourRoute.setTrName(sc.nextLine());
        System.out.print("类型(1、自由行  2、纯玩团)：");
        String trType = sc.nextLine();
        tourRoute.setTrType(Integer.parseInt(trType));
        System.out.print("请输入价格：");
        String trPrice = sc.nextLine();
        tourRoute.setTrPrice(Double.parseDouble(trPrice));
        System.out.print("请输入咨询人：");
        tourRoute.setTrUser(sc.nextLine());
        System.out.print("请输入咨询电话：");
        tourRoute.setTrPhone(sc.nextLine());
        tourRoute.setCreateTime(date.format(formatter));
        int addRes = tourRouteDao.insert(tourRoute);
        System.out.println(addRes > 0 ? "录入成功" : "录入失败");
    }
    public void deleteTourRouteInfo(TourRouteDao tourRouteDao, Scanner sc){
        System.out.print("请输入要删除的旅游路线名称：");
        String trName = sc.nextLine();
        int addRes = tourRouteDao.delete(trName);
        System.out.println(addRes > 0 ? "删除成功" : "删除失败");
    }
}
